<?php
class Alliance_redis extends Common_redis_model{
	public function __construct(array $params = array()) 
	{
		parent::__construct();
		$this->params=$params;
	}

	function get_alliance_data($node, $limit = 0, $offset = 10) {
		$lists = $score = array();
		$key = $this->params['channel'].$node.":sort";
		
		$star 	= !empty($limit)? $limit * $offset : $limit;
		$end	= !empty($offset) ? $offset * ($limit +1)  : $offset;
		$count = (int) $this->redis->zSize($key);

		if( !empty($count)) {
			$score	= $this->redis->zRevRange($key, $star, ($end-1), FALSE);
			if(!empty($score)) {
				foreach($score as $key=>$val) {
					$lists[] = $this->get_alliance($this->params['channel'] . $node . ":" . $val);
				}
			}
		}
		return $lists;
	}

	function get_alliance( $redis_anchor_key = '' ) {
		$redis_anchor_item = $this->redis->hgetall($redis_anchor_key);
		return $redis_anchor_item;
	}
	
	function del_all(){
		$keys = $this->redis->keys($this->params['channel']."*");
		$this->redis->del($keys);
	}
	/*function get_ranking_data( $redis_anchor_key = '' ) {
		$redis_anchor_item = $this->redis->hgetall($this->params['channel'].$redis_anchor_key);
		return $redis_anchor_item;
	}*/
}